const mongoose = require("../db/mongodb.js");

const onlineMsgSchema = mongoose.Schema({
    username: {
        type: String,
        required: [true, "不能为空"]
    },
    tel: {
        type: String,
        required: [true, "不能为空"],
        validate: {
            validator: function (v) {
                return /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/.test(v);
            },
            message: '{VALUE} 不是正确格式的电话号码'
        },
    },
    email: {
        type: String,
        required: [true, "不能为空"],
        validate: {
            validator: function (v) {
                return /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(v);
            },
            message: '{VALUE} 不是正确格式的邮箱'
        },
    },
    content: {
        type: String,
        required: [true, "不能为空"],
        maxlength: [150, '不得多于150个字']
    }
}, { timestamps: true });
const onlineMsgModel = mongoose.model("OnlineMsg", onlineMsgSchema);
onlineMsgModel.fields = {
    username: "用户名",
    tel: "联系方式",
    email: "邮箱",
    content: "内容"
}
module.exports = onlineMsgModel